using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.InteropServices;
using System.Drawing;

namespace SystemFunctionLib.Apis
{
    [StructLayout(LayoutKind.Sequential)]
    internal struct SYSTEMTIME
    {
        [MarshalAs(UnmanagedType.U2)]
        public ushort wYear;
        [MarshalAs(UnmanagedType.U2)]
        public ushort wMonth;
        [MarshalAs(UnmanagedType.U2)]
        public ushort wDayOfWeek;
        [MarshalAs(UnmanagedType.U2)]
        public ushort wDay;
        [MarshalAs(UnmanagedType.U2)]
        public ushort wHour;
        [MarshalAs(UnmanagedType.U2)]
        public ushort wMinute;
        [MarshalAs(UnmanagedType.U2)]
        public ushort wSecond;
        [MarshalAs(UnmanagedType.U2)]
        public ushort wMilliseconds;

        public static SYSTEMTIME FromDateTime(DateTime time)
        {
            SYSTEMTIME systime;

            systime.wYear = (ushort)time.Year;
            systime.wMonth = (ushort)time.Month;
            systime.wDayOfWeek = (ushort)time.DayOfWeek;
            systime.wDay = (ushort)time.Day;
            systime.wHour = (ushort)time.Hour;
            systime.wMinute = (ushort)time.Minute;
            systime.wSecond = (ushort)time.Second;
            systime.wMilliseconds = (ushort)time.Millisecond;

            return systime;
        }

        public DateTime ToLocalDateTime()
        {
            return new DateTime(
                wYear, wMonth, wDay, 
                wHour, wMinute, wSecond, wMilliseconds, 
                DateTimeKind.Local);
        }

        public DateTime ToUtcDateTime()
        {
            return new DateTime(
                wYear, wMonth, wDay,
                wHour, wMinute, wSecond, wMilliseconds,
                DateTimeKind.Utc);
        }
    }

    [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
    internal struct TIME_ZONE_INFORMATION
    {
        [MarshalAs(UnmanagedType.I4)]
        public int Bias;

        [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 32)]
        public string StandardName;

        public SYSTEMTIME StandardDate;
        
        [MarshalAs(UnmanagedType.I4)]
        public int StandardBias;
        
        [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 32)]
        public string DaylightName;

        public SYSTEMTIME DaylightDate;
        
        [MarshalAs(UnmanagedType.I4)]
        public int DaylightBias;
    }

    internal enum TimeZoneResult : uint
    {
        Unknown = 0,
        Standard = 1,
        Daylight = 2,
        Invalid = 0xFFFFFFFF,
    }
}